<template>
  <div class="infoContent">
    <!-- 标题--> 
    <h1>{{info.title}}</h1>
     <!-- 子标题--> 
    <p class="subtitle">
      <span>发表时间:{{info.add_time | dateFormat}}</span>
      <span>点击：{{ info.click }}</span>
    </p>
    <!-- 内容 -->
    <div class="content" v-html="info.content"></div>
    <!-- 评论区 -->
   
      <comment-box :id="this.id"></comment-box>
    
  </div>
</template>

<script>
// 1. 导入评论子组件
import comment from '../subcomponent/comment.vue'

export default {
  data() {
    return {
      id: this.$route.params.id, //将url地址中传递过来的id值，挂载到data上，方便调用
      info: [], //新闻对象
    };
  },
  created() {
    this.getNewsInfo();
  },
  methods: {
    getNewsInfo() {
        var _this =  this 
      _this.$http
        .get("http://api.cms.liulongbin.top/api/getnew/" + this.id)
        .then(function (res) {
          if (res.data.status === 0) {
            _this.info = res.data.message[0];
          } else {
            Toast("加载新闻信息失败");
          }
        });
    },
  },
  components:{
    //用来注册子组件的节点
    'comment-box':comment

  }
};
</script>

<style lang="scss">
.infoContent {
  padding: 0 4px;
  h1 {
    text-align: center;
    font-size: 14px;
    color: red;
    margin: 12px 0;
  }
  .subtitle {
    font-size: 13px;
    color: #226afa;
    display: flex;
    justify-content: space-between;
  }
  .content {
    border-top: 1px solid gray;
    padding-top: 10px;
    color: gray;
    width: 100%;
  }
}
</style>